#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\models\marketmodels\pathwisegreeks\vegabumpcluster.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Models::Marketmodels;
#undef HANDLE
#undef ABSTRACT
#define STRUCT
namespace Cephei { namespace QL { namespace Models { namespace Marketmodels { namespace Pathwisegreeks {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IVegaBumpCluster
	public ref class CVegaBumpCluster  : 
            public Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster
	{
	protected: 
		boost::shared_ptr<QuantLib::VegaBumpCluster>* _ppVegaBumpCluster;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::VegaBumpCluster>* _phVegaBumpCluster;
#endif
		Object^ _VegaBumpClusterOwner;     // reference to object that manages the storage for this object
	internal:
		CVegaBumpCluster (UInt64 factorBegin, UInt64 factorEnd, UInt64 rateBegin, UInt64 rateEnd, UInt64 stepBegin, UInt64 stepEnd);
        CVegaBumpCluster (boost::shared_ptr<QuantLib::VegaBumpCluster>& childNative, Object^ owner);
        CVegaBumpCluster (QuantLib::VegaBumpCluster& childNative, Object^ owner);
        CVegaBumpCluster (CVegaBumpCluster^ copy);
        CVegaBumpCluster (PLATFORM::Type^ t);
#ifdef STRUCT
        CVegaBumpCluster (QuantLib::VegaBumpCluster childNative);
#endif       
#ifdef HANDLE
		CVegaBumpCluster (QuantLib::Handle<QuantLib::VegaBumpCluster>& childNative, Object^ owner);
		CVegaBumpCluster (QuantLib::Handle<QuantLib::VegaBumpCluster> childNative);
#endif
		virtual ~CVegaBumpCluster ();
		!CVegaBumpCluster ();

	internal:
		QuantLib::VegaBumpCluster& GetReference ();
		boost::shared_ptr<QuantLib::VegaBumpCluster>& GetShared ();
		QuantLib::VegaBumpCluster* GetPointer ();
        void SetVegaBumpCluster (boost::shared_ptr<QuantLib::VegaBumpCluster> native)
        {
            if (_ppVegaBumpCluster != NULL)
                delete _ppVegaBumpCluster;
            _ppVegaBumpCluster = new boost::shared_ptr<QuantLib::VegaBumpCluster> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::VegaBumpCluster>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
		virtual Boolean DoesIntersect (Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^ comparee) ;
        property UInt64 FactorBegin 
        {
		    virtual UInt64 get () ;
        }
        property UInt64 FactorEnd 
        {
		    virtual UInt64 get () ;
        }
		virtual Boolean IsCompatible (Cephei::QL::Models::Marketmodels::IMarketModel^ volStructure) ;
        property UInt64 RateBegin 
        {
		    virtual UInt64 get () ;
        }
        property UInt64 RateEnd 
        {
		    virtual UInt64 get () ;
        }
        property UInt64 StepBegin 
        {
		    virtual UInt64 get () ;
        }
        property UInt64 StepEnd 
        {
		    virtual UInt64 get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IVegaBumpCluster Vector interface
	ref class CVegaBumpClusterVector sealed : 
							    public Core::INativeVector<IVegaBumpCluster^>,
							    public Core::INativeVector<Core::Generic::ICoCell<IVegaBumpCluster^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::VegaBumpCluster>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::VegaBumpCluster>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::VegaBumpCluster>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CVegaBumpClusterVector ();
#ifdef STRUCT
		CVegaBumpClusterVector (std::vector<QuantLib::VegaBumpCluster>& vec, Object^ owner);
		CVegaBumpClusterVector (std::vector<QuantLib::VegaBumpCluster> vec);
#endif       
		CVegaBumpClusterVector (std::vector<boost::shared_ptr<QuantLib::VegaBumpCluster>>& vec, Object^ owner);
#ifdef HANDLE
		CVegaBumpClusterVector (std::vector<QuantLib::Handle<QuantLib::VegaBumpCluster>>& vec, Object^ owner);
#endif
		virtual ~CVegaBumpClusterVector ();
		!CVegaBumpClusterVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IVegaBumpCluster^ default[int] 
		{
			virtual IVegaBumpCluster^ get (int index) = Core::INativeVector<IVegaBumpCluster^>::default::get;
			virtual void set (int index, IVegaBumpCluster^ value) = Core::INativeVector<IVegaBumpCluster^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Core::Generic::ICoCell<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ CItem[int] 
		{
			virtual Core::Generic::ICoCell<IVegaBumpCluster^>^ get (int index) = Core::INativeVector<Core::Generic::ICoCell<IVegaBumpCluster^>^>::default::get;
			virtual void set (int index, Core::Generic::ICoCell<IVegaBumpCluster^>^ value) = Core::INativeVector<Core::Generic::ICoCell<IVegaBumpCluster^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::VegaBumpCluster>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::VegaBumpCluster>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::VegaBumpCluster>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>::typeid)]
	[FactoryFor(Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster::typeid)]
	[FactoryFor(Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster_Factory::typeid)]
	public ref class CVegaBumpCluster_Factory sealed : public IVegaBumpCluster_Factory
	{
	public:
        virtual IVegaBumpCluster^ Create (UInt64 factorBegin, UInt64 factorEnd, UInt64 rateBegin, UInt64 rateEnd, UInt64 stepBegin, UInt64 stepEnd);
        /* <summary> Create a hybrid Vector of IVegaBumpCluster, with event notification of changes </summary> */
        virtual Cephei::Core::IVector<IVegaBumpCluster^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IVegaBumpCluster, with event notification of changes </summary> */
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IVegaBumpCluster^>^>^>^ CreateCellVector();
        virtual Cephei::Core::IVector<IVegaBumpCluster^>^ CreateVector(PLATFORM::Collections::Generic::IEnumerable<IVegaBumpCluster^>^ source);
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IVegaBumpCluster^>^>^>^ CreateCellVector(PLATFORM::Collections::Generic::IEnumerable<Core::Generic::ICoCell<IVegaBumpCluster^>^>^ source);
		virtual Core::INativeVector<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ CreateNativeVector ()
		{
			return REFNEW CVegaBumpClusterVector ();
		}

        virtual Core::INativeMatrix<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ CreateNativeMatrix ()
		{
			return nullptr;
		}

        virtual Core::INativeCube<Cephei::QL::Models::Marketmodels::Pathwisegreeks::IVegaBumpCluster^>^ CreateNativeCube ()
		{
			return nullptr;
		}
    };
   
/*Cephei*/ } /*QL*/ } /*Models*/ } /*Marketmodels*/ } /*Pathwisegreeks */}
